package org.yoao.crm.acl;

import org.yoao.crm.bean.StaticBean;

public class ACLTool {

	public static boolean isAdmin(final String roleId){
		return StaticBean.ROLE_ADMIN.equals(roleId);
	}

	public static String getActionPermission(final String actionPermission){
		if(actionPermission == null || actionPermission.trim().equals("")) return "";
		String[] actionPermissions = actionPermission.split(";");
		if(actionPermissions == null || actionPermission.length() == 0) return "";
		StringBuffer ap = new StringBuffer();
		for(String key : actionPermissions){
			ap.append(ACLConstants.ACTION_PERMISSION_MAP.get(key) + "  ");
		}
		return ap.toString();
	}

	public static boolean isSearch(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_SEARCH+ ";");
	}
	
	public static boolean isSearchAll(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_SEARCH_ALL+ ";");
	}

	public static boolean isAdd(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_NEW + ";");
	}

	public static boolean isModify(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_MODIFY + ";");
	}

	public static boolean isDelete(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_DELETE + ";");
	}

	public static boolean isDownloadTemplate(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_DOWNLOADTEMPLATE + ";");
	}

	public static boolean isExportOut(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_EXPORTOUT + ";");
	}

	public static boolean isExportIn(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_EXPORTIN + ";");
	}

	public static boolean isSignatureYes(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_SIGNATURE_YES + ";");
	}

	public static boolean isSignatureNo(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_SIGNATURE_NO + ";");
	}

	public static boolean isAllocation(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_ALLOCATION + ";");
	}

	public static boolean isCustType(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_CUST_TYPE + ";");
	}

	public static boolean isOpenUser(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_OPEN_USER + ";");
	}

	public static boolean isCloseUser(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_CLOSE_USER + ";");
	}

	public static boolean isSms(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_SMS + ";");
	}

	public static boolean isSuccess(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_SUCCESS + ";");
	}

	public static boolean isModifyMemo(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_MODIFY_MEMO + ";");
	}

	public static boolean isCancel(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_CANCEL + ";");
	}

	public static boolean isAudit(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_AUDIT + ";");
	}

	public static boolean isPay(final String actionPermission){
		String actionPermissions = ";" + (actionPermission != null ? actionPermission : "") + ";";
		return actionPermissions.contains(";" + ACLConstants.AP_PAY+ ";");
	}
}
